import { ref } from 'vue';
import { getAccountsPayableDetailApi } from '@/api/sj/financialManagement/accountsPayable'
import { getAccountsReceivableApi } from '@/api/sj/financialManagement/accountsReceivable/index';



const useReconciliationDetails = () => {

    const reconciliationDetailsVisible = ref(false);
    const paymentDetailsVisible = ref(false);
    const paymentDetails = ref<any>();
    const paymentDetailsRow = ref<any>();

    /** 打开 对账详情 弹窗 */
    const handlOpenReconciliationDetails = async (row: any) => {
        reconciliationDetailsVisible.value = true;
    };

    /** 关闭 对账详情 弹窗 */
    const handleReconciliationDetailsClose = () => {
        reconciliationDetailsVisible.value = false;
    };

    /** 打开 付款详情 弹窗 */
    const handlOpenPaymentDetails = async (row: any) => {
        paymentDetailsRow.value = row
        getPaymentDetails(row);
        paymentDetailsVisible.value = true;
    };

    /** 打开收款详情 */
    const handlOpenReceivableDetails = async (row: any) => {
        paymentDetailsRow.value = row
        getReceivableDetails(row);
        paymentDetailsVisible.value = true;
    };

    /** 付款详情 */
    const getPaymentDetails = async (row: any) => {
        try {
            const {data} = await getAccountsPayableDetailApi(row.id);
            paymentDetails.value = data;
        } catch (error) {
            
        }
    };

    /** 收款详情 */
    const getReceivableDetails = async (row: any) => {
        try {
            const {data} = await getAccountsReceivableApi(row.id);
            paymentDetails.value = data;
        } catch (error) {
            
        }
    };

    return {
        reconciliationDetailsVisible,
        paymentDetailsVisible,
        paymentDetailsRow,
        paymentDetails,
        handlOpenReceivableDetails,
        handlOpenPaymentDetails,
        handlOpenReconciliationDetails,
        handleReconciliationDetailsClose
    }
};

export default useReconciliationDetails;
